package com.example.demo.service;

import com.example.demo.mapper.AdministratorMapper;
import com.example.demo.model.Administrator;
import com.example.demo.tools.Constant;
import com.example.demo.tools.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Service
public class AdministratorService {
    // 注入 LoginMapper 依赖
    @Autowired
    private AdministratorMapper administratorMapper;


    public ResponseBodyMessage<Administrator> select(String username, String password, HttpServletRequest request) {
        Administrator user = administratorMapper.select(username,password);
        if (user != null) {
            HttpSession session = request.getSession();
            session.setAttribute(Constant.SESSION_KEY_USERINFO, user);
            return new ResponseBodyMessage<>(200, "登陆成功", user);
        } else {
            return new ResponseBodyMessage<>(400, "登陆失败", null);
        }
    }

}
